<template>
  <div class="app-container">
    <el-form ref="teamRef" :model="form" :rules="rules" label-width="150px">
        <el-row>
            <el-col :span="6">
                <el-form-item label="成立时间" prop="establishDated">
                    <el-date-picker clearable
                        v-model="form.establishDated"
                        type="date"
                        value-format="YYYY-MM-DD"
                        placeholder="请选择成立时间">
                    </el-date-picker>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="团体名称" prop="teamName">
                    <el-input v-model="form.teamName" placeholder="请输入团体名称" />
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="公司名称" prop="companyName">
                    <el-input v-model="form.companyName" placeholder="请输入公司名称" />
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="统一信用代码" prop="companyCard">
                    <el-input v-model="form.companyCard" placeholder="请输入统一信用代码" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="团队二维码" prop="qrcode">
                <image-preview :src="form.qrcode" :width="170" :height="170"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="团队logo" prop="logo">
                    <image-upload v-model="form.logo" :limit="1" :file-size="1"/>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="营业执照" prop="businessLicense">
                    <image-upload v-model="form.businessLicense" :limit="1" :fileSize="2"/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="团队海报" prop="poster">
                    <image-upload v-model="form.poster" :limit="1" :file-size="2"/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="团队照" prop="photo">
                    <image-upload v-model="form.photo" :limit="1" :fileSize="2"/>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="队伍类型" prop="teamCategory">
                    <el-select v-model="form.teamCategory" placeholder="请选择队伍类型">
                        <el-option
                        v-for="dict in cl_team_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                        ></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="18">
                <el-form-item label="队伍口号" prop="teamSolo">
                    <el-input v-model="form.teamSolo" placeholder="请输入队伍口号" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="法人" prop="legalPerson">
                    <el-input v-model="form.legalPerson" placeholder="请输入法人" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="加入方式" prop="joinType">
                <el-select v-model="form.joinType" placeholder="请选择加入方式">
                    <el-option
                    v-for="dict in cl_team_join_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                    ></el-option>
                </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="邮箱" prop="email">
                <el-input v-model="form.email" placeholder="请输入邮箱" />
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item label="队伍介绍" prop="teamDesc">
                  <el-input v-model="form.teamDesc" type="textarea" placeholder="请输入队伍介绍" :autosize="{ minRows: 6, maxRows: 20 }"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item label="负责人手持证件照" prop="leaderIdPhoto">
                <image-upload v-model="form.leaderIdPhoto" :limit="1" :file-size="2"/>  
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="负责人" prop="leader">
                <el-input v-model="form.leader" placeholder="请输入负责人" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="负责人联系方式" prop="leaderPhone">
                <el-input v-model="form.leaderPhone" placeholder="请输入负责人联系方式" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="负责人身份证号" prop="leaderId">
                <el-input v-model="form.leaderId" placeholder="请输入负责人身份证号" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="主要联系人" prop="teamContacts">
                <el-input v-model="form.teamContacts" placeholder="请输入主要联系人" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="主要联系人电话" prop="teamPhone">
                <el-input v-model="form.teamPhone" placeholder="请输入主要联系人电话" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="主要联系人身份证号" prop="teamContactsId">
                <el-input v-model="form.teamContactsId" placeholder="请输入主要联系人身份证号" />
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="是否公开" prop="isPublicly">
                <el-select v-model="form.isPublicly" placeholder="请选择是否公开">
                    <el-option
                    v-for="dict in cl_is_publicly"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                    ></el-option>
                </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="所在区域" prop="area">
                <el-select v-model="form.area" placeholder="请选择所在区域">
                    <el-option
                    v-for="dict in cl_team_area"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                    ></el-option>
                </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="地址" prop="address">
                <el-input v-model="form.address" placeholder="请输入地址" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="登记/审计的部门" prop="auditGroup">
                <el-input v-model="form.auditGroup" placeholder="请输入登记/审计的部门" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="管理部门" prop="manageGroup">
                <el-input v-model="form.manageGroup" placeholder="请输入管理部门" />
                </el-form-item>
            </el-col>
            <el-col :span="8">
            <el-form-item label="审核状态" prop="status">
            <el-select v-model="form.status" placeholder="请选择审核状态" aria-readonly="true">
                <el-option
                v-for="dict in cl_team_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
                ></el-option>
            </el-select>
            </el-form-item>
            </el-col>
            <el-form-item label="备注" prop="remark" v-if="false">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
            <el-form-item label="经度" prop="longitude" v-if="false">
            <el-input v-model="form.longitude" placeholder="请输入经度" />
            </el-form-item>
            <el-form-item label="纬度" prop="latitude" v-if="false">
            <el-input v-model="form.latitude" placeholder="请输入纬度" />
            </el-form-item>
            <el-form-item label="经纬度" prop="lonlat" v-if="false">
            <el-input v-model="form.lonlat" placeholder="请输入经纬度" />
            </el-form-item>
            <el-col :span="24">
                <el-form-item label="服务类别" prop="serviceType">
                    <el-checkbox-group v-model="form.serviceType">
                        <el-checkbox
                        v-for="dict in cl_team_service_type"
                        :key="dict.value"
                        :label="dict.value">
                        {{dict.label}}
                        </el-checkbox>
                    </el-checkbox-group>
                </el-form-item>
            </el-col>
        </el-row>
      </el-form>
       <el-row type="flex" justify="center">
        <el-button type="primary" @click="submitForm">确 定</el-button>
       </el-row>
  </div>
</template>

<script setup>
import { listTeam, getTeam, delTeam, addTeam, updateTeam, getTeamInfo } from "@/api/ndpf/team";
const { proxy } = getCurrentInstance();
const { cl_is_publicly, cl_team_type, cl_team_join_type, cl_team_area, cl_team_service_type, cl_team_status } = proxy.useDict('cl_is_publicly', 'cl_team_type', 'cl_team_join_type', 'cl_team_area', 'cl_team_service_type', 'cl_team_status');

const data = reactive({
  form: {},
  rules: {
    serviceType: [
      { required: true, message: "服务类别不能为空", trigger: "blur" }
    ],
    establishDated: [
      { required: true, message: "成立时间不能为空", trigger: "blur" }
    ],
    teamName: [
      { required: true, message: "团体名称不能为空", trigger: "blur" }
    ],
    companyName: [
      { required: true, message: "公司名称不能为空", trigger: "blur" }
    ],
    teamCategory: [
      { required: true, message: "队伍类型不能为空", trigger: "change" }
    ],
    joinType: [
      { required: true, message: "加入方式不能为空", trigger: "change" }
    ],
    legalPerson: [
      { required: true, message: "法人不能为空", trigger: "blur" }
    ],
    leader: [
      { required: true, message: "负责人不能为空", trigger: "blur" }
    ],
    leaderPhone: [
      { required: true, message: "负责人联系方式不能为空", trigger: "blur" }
    ],
    leaderId: [
      { required: true, message: "负责人身份证号不能为空", trigger: "blur" }
    ],
    teamContacts: [
      { required: false, message: "主要联系人不能为空", trigger: "blur" }
    ],
    teamPhone: [
      { required: false, message: "主要联系人电话不能为空", trigger: "blur" }
    ],
    teamContactsId: [
      { required: false, message: "主要联系人身份证不能为空", trigger: "blur" }
    ],
    isPublicly: [
      { required: true, message: "是否公开不能为空", trigger: "change" }
    ],
    logo: [
      { required: true, message: "团队logo不能为空", trigger: "blur" }
    ],
    poster: [
      { required: false, message: "团队海报不能为空", trigger: "blur" }
    ],
    photo: [
      { required: false, message: "团队照不能为空", trigger: "blur" }
    ],
    email: [
      { required: false, message: "邮箱不能为空", trigger: "blur" }
    ],
    area: [
      { required: true, message: "所在区域不能为空", trigger: "change" }
    ],
    address: [
      { required: true, message: "地址不能为空", trigger: "blur" }
    ],
    status: [
      { required: true, message: "0未审核1审核启用2停用3删除不能为空", trigger: "change" }
    ]
    ,businessLicense: [
      { required: true, message: "营业执照不能为空", trigger: "change" }
    ],
  }
});

const { form, rules } = toRefs(data);


/** 提交按钮 */
function submitForm() {
  proxy.$refs["teamRef"].validate(valid => {
      if (valid) {
      form.value.serviceType = form.value.serviceType.join(",");
        if (form.value.teamId != null) {
          updateTeam(form.value).then(response => {
            proxy.$modal.msgSuccess("修改成功");
            getTeamInfos();
          });
        }
    }
  });
}

/** 修改按钮操作 */
function getTeamInfos() {
  getTeamInfo().then(response => {
    form.value = response.data;
    form.value.serviceType = form.value.serviceType.split(",");
  });
}

getTeamInfos();

</script>
